package 分治;

/**
 * @description:
 * @author: ywk
 * @date: 2020-12-20
 */
public class 寻找右侧边界的二搜索 {
    public static void main(String[] args) {
        System.out.println(binarySearchRightBound(new int[]{1, 2, 2, 2, 3, 5}, 8));
    }

    public static int binarySearchRightBound(int[] nums, int target) {
        int left = 0;
        int right = nums.length - 1;
        while (left <= right) {
            int mid = left + (right - left) / 2;
            if (nums[mid] == target) {
                left = mid + 1;
            } else if (nums[mid] < target) {
                left = mid + 1;
            } else if (nums[mid] > target) {
                right = mid - 1;
            }
        }
        return left;
    }
}
